CREATE TABLE [dbo].[Accounts]
(
[AccountId] [int] NOT NULL IDENTITY(1, 1),
[FirstName] [varchar] (30) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[LastName] [varchar] (30) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[Email] [varchar] (150) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[Phone] [varchar] (15) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[Address1] [varchar] (150) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[Address2] [varchar] (150) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[Address3] [varchar] (150) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[City] [varchar] (30) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[State] [varchar] (2) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[Postal] [varchar] (15) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[Country] [varchar] (30) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[Username] [varchar] (30) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[Password] [varchar] (30) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[BirthDate] [smalldatetime] NULL,
[CreateDate] [smalldatetime] NULL,
[LastUpdateDate] [smalldatetime] NULL
)

ALTER TABLE [dbo].[Accounts] ADD CONSTRAINT [PK_Accounts] PRIMARY KEY CLUSTERED  ([AccountId])

CREATE TABLE [dbo].[AccountPermissions]
(
[ApId] [int] NOT NULL IDENTITY(1, 1),
[AccountId] [int] NOT NULL,
[PermissionId] [int] NOT NULL
)

ALTER TABLE [dbo].[AccountPermissions] ADD CONSTRAINT [PK_AccountPermissions] PRIMARY KEY CLUSTERED  ([apid])

CREATE TABLE [dbo].[Permissions]
(
[PermissionId] [int] NOT NULL IDENTITY(1, 1),
[Name] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL
)

ALTER TABLE [dbo].[Permissions] ADD CONSTRAINT [PK_Permissions] PRIMARY KEY CLUSTERED  ([PermissionId])

CREATE TABLE [dbo].[Profiles]
(
[ProfileId] [int] NOT NULL IDENTITY(1, 1),
[AccountId] [int] NOT NULL,
[ProfileName] [varchar] (100) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[CreateDate] [smalldatetime] NULL,
[LastUpdateDate] [smalldatetime] NULL
)

ALTER TABLE [dbo].[AccountPermissions] ADD
CONSTRAINT [FK_AccountPermissions_Accounts] FOREIGN KEY ([AccountId]) REFERENCES [dbo].[Accounts] ([AccountId]),
CONSTRAINT [FK_AccountPermissions_Permissions] FOREIGN KEY ([PermissionId]) REFERENCES [dbo].[Permissions] ([PermissionId])
ALTER TABLE [dbo].[Profiles] ADD
CONSTRAINT [FK_Profiles_Accounts] FOREIGN KEY ([AccountId]) REFERENCES [dbo].[Accounts] ([AccountId])
